import pygame
from pygame.locals import *

from glyph import Glyph, Macros

from menu import *
#from constants import * # Seems not necessary, constants are already imported by the Menu class.

class Main:
	"""Class initializing the windown, displaying the credits and launching the main menu.
	-- Class variables --
	isRunning     : boolean : Condition for the main loop to run.
	menu          : Menu  : Contains current game's configuration.
	window        : Pygame : Main window of the game.
	-- Class public methods --
	run           : None    : Main loop of the program.
	"""
	
	def __init__(self):
		self.window = pygame.display.set_mode((WindowDefaultWidth, WindowDefaultHeigth))
		self.menu = Menu(self.window)
		self.glyph = Glyph(CLIP, **DEFAULT)
		Macros['big'] = ('font', pygame.font.Font(os.path.join("texts", "silkscreen.ttf"), 15))
		Macros['red'] = ('color', (255, 0, 0))
		Macros['green'] = ('color', (0, 255, 0))

	def run(self):
		"""Method launching the menu loop.
		-- Inputs --
		None
		-- Outputs --
		None
		"""
		glyph = self.glyph # facultatif
		glyph_rect = glyph.rect # fac
		message_number = 0
		glyph.input(CreditsText[message_number], justify = 'left')
		glyph.update()
		glyph.image = glyph.image.convert_alpha()
		self.window.blit(glyph.image, glyph_rect)
		pygame.display.flip()
		pygame.time.wait(5000)
		
		self.menu.run()
		return 0

pygame.font.init()

#glyph constants
CLIP = Rect(0, 0, 432, 324)
CLIP.center = (WindowDefaultWidth/2, WindowDefaultHeigth/2)

FONT = pygame.font.Font("texts%ssilkscreen.ttf"%(os.sep), 12)
DEFAULT = {
	'bkg'       : (11, 11, 11),
	'color'     : (201, 192, 187),
	'font'      : FONT,
	'spacing'   : FONT.get_linesize(),
}

# Credits
CreditsText = {
	0 : """
{green;##############################}
{green;#} {big; Welcome to <A Geek's Knight>} {green;#}
{green;##############################}
/n
{green;-----------------}{big; demo }{green;-----------------}
/n
{big; Authors:}
Gael Jalowicki and Kevin Rue
/n
(c)GameKit 2011.
"""
}
